package com.fbt.energy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fbt.energy.dao.AmmeterDao;
import com.fbt.energy.entity.Ammeter;
import com.fbt.energy.entity.ExceptionRecord;
import com.fbt.energy.dao.ExceptionRecordDao;
import com.fbt.energy.service.ExceptionRecordService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 能耗异常表(ExceptionRecord)表服务实现类
 *
 * @author makejava
 * @since 2021-12-12 19:06:38
 */
@Service("exceptionRecordService")
public class ExceptionRecordServiceImpl  extends ServiceImpl<ExceptionRecordDao,ExceptionRecord> implements ExceptionRecordService {
    @Resource
    private ExceptionRecordDao exceptionRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ExceptionRecord queryById(Integer id) {
        return this.exceptionRecordDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param exceptionRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ExceptionRecord> queryByPage(ExceptionRecord exceptionRecord, PageRequest pageRequest) {
        long total = this.exceptionRecordDao.count(exceptionRecord);
        return new PageImpl<>(this.exceptionRecordDao.queryAllByLimit(exceptionRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param exceptionRecord 实例对象
     * @return 实例对象
     */
    @Override
    public ExceptionRecord insert(ExceptionRecord exceptionRecord) {
        this.exceptionRecordDao.insert(exceptionRecord);
        return exceptionRecord;
    }

    /**
     * 修改数据
     *
     * @param exceptionRecord 实例对象
     * @return 实例对象
     */
    @Override
    public ExceptionRecord update(ExceptionRecord exceptionRecord) {
        this.exceptionRecordDao.update(exceptionRecord);
        return this.queryById(exceptionRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.exceptionRecordDao.deleteById(id) > 0;
    }
}
